import 'package:flutter/material.dart';
import 'package:x3_base_core/x3_base_core.dart';
import 'package:x3_business_core/common_components/business_depot_customer.dart';
import 'package:x3_business_core/common_components/business_retails_order_history.dart';
import 'package:x3_component_core/x3_component_core.dart';

import 'business_components/business_clerk_files.dart';
import 'business_components/business_clerk_details_header.dart';

class BusinessClerkDetails extends StatefulWidget {
  static final String sName = 'BusinessClerkDetailsBusinessClerkDetails';

  @override
  _BusinessClerkDetailsState createState() => _BusinessClerkDetailsState();
}

class _BusinessClerkDetailsState extends State<BusinessClerkDetails> {
  @override
  Widget build(BuildContext context) {
    dynamic arguments = BaseRouterUtil.getArguments(context);
    String userId = BaseUtils.getKeyData(arguments, 'userId').toString();
    assert(userId.isNotEmpty);
    return BaseScaffoldComponent(
      title: '员工详情',
      child: DefaultTabController(
        length: 3,
        child: BaseNestedScrollView(
          headerWidget: buildHeaderWidget(userId: userId),
          pinnedWidget: BaseNestedScrollPinned(height: 44.0, child: buildPinnedWidget()),
          contentWidget: buildContentWidget(userId: userId),
        ),
      ),
    );
  }

  Widget buildHeaderWidget({@required String userId}) {
    return BusinessClerkDetailsHeader(userId: userId);
  }

  Widget buildPinnedWidget() {
    return BaseCardComponent(
      padding: EdgeInsets.zero,
      margin: EdgeInsets.symmetric(horizontal: 16.0),
      circular: 4,
      child: Container(
        height: 44,
        child: TabBar(
          indicatorSize: TabBarIndicatorSize.tab,
          tabs: [
            Text('档案'),
            Text('会员'),
            Text('开单'),
          ],
        ),
      ),
    );
  }

  Widget buildContentWidget({@required String userId}) {
    return TabBarView(children: [
      buildClerkFiles(userId: userId),
      buildQueryClerkCustomer(userId: userId),
      buildClerkRetailsOrder(userId: userId),
    ]);
  }

  /// 档案
  Widget buildClerkFiles({@required String userId}) {
    return BusinessClerkFiles(userId: userId);
  }

  /// 会员
  Widget buildQueryClerkCustomer({@required String userId}) {
    return BusinessCustomer(businessId: userId, queryType: 'MyUser');
  }

  /// 开单
  Widget buildClerkRetailsOrder({@required String userId}) {
    return BusinessRetailsOrderHistory(businessId: userId, queryType: 'MyUser');
  }
}
